const App = getApp();
import { url } from '../../../../modelApi/url_config.js'
Page({
	data: {
		statusBarHeight: "",
		statusBarPadding: "",
		chagneFlag: true,
		pageobj: {
			pageNo: 1,
			pageSize: 10
		},
		type: '1',
		hasNextPage: true,
		inforList:[]  // 消息列表
	},
	onLoad: function (options) {
		this.setData({
			statusBarPadding: App.globalData.navTop,
			statusBarHeight: App.globalData.navHeight,
		});
	},
	onShow() {
		this.setData({
			inforList:[]
		})
		this.onLoadList()
		
	},
	onLoadList() {
		const par = {
			// type: this.data.chagneFlag ? '1' : '2'
			type: 0
		}
		App.ajax(url.messageList, {...par, ...this.data.pageobj}, 'get').then(res => {
			if (res.code === 0) {
				this.data.inforList = [...this.data.inforList, ...res.rows]
                this.setData({
					inforList: this.data.inforList,
					hasNextPage: res.hasNextPage
				})
            }
        }).catch(err => {
            console.log(err)
        })
	},
	changeTab(e) {
		if (this.data.type === e.currentTarget.dataset.type) return
		this.data.pageobj.pageNo = 1;
		this.data.inforList = []; 
		this.setData({
			chagneFlag: e.currentTarget.dataset.type === '1',
			type: e.currentTarget.dataset.type,
			pageobj: this.data.pageobj
		})
		this.onLoadList();
	},
	bindscrolltolower() {
		if (this.data.hasNextPage) {
			this.data.pageobj.pageNo++;
			this.setData({
				pageobj: this.data.pageobj
			})
			this.onLoadList();
		}
	}
})